package com.qf.java2102.qihaonan.hotel.controller.dinnertable;

import com.alibaba.fastjson.JSON;
import com.qf.java2102.qihaonan.hotel.entity.ResultVO;
import com.qf.java2102.qihaonan.hotel.service.IDinnerTableService;
import com.qf.java2102.qihaonan.hotel.service.impl.DinnerTableServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author qhn
 * @version 1.0
 */
@WebServlet("/dinnerTable/findByTableStatus")
public class DinnerTableController extends HttpServlet {

    private IDinnerTableService dinnerTableService = new DinnerTableServiceImpl();

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ResultVO<Map> resultVO = null;
        try {
            String statusStr = request.getParameter("status");
            Integer status = Integer.valueOf(statusStr);
            resultVO = dinnerTableService.findByTableStatus(status);

            //菜系列表
            request.getSession().setAttribute("types", resultVO.getData().get("types"));
            //可用餐桌列表
            response.getWriter().write(JSON.toJSONString(resultVO));
            return;
        } catch (Exception e){
            e.printStackTrace();
        }
        response.getWriter().write(JSON.toJSONString(resultVO));
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
